package cn.wolfcode.edu.web.controller;

import cn.wolfcode.edu.domain.ExpenseBook;
import cn.wolfcode.edu.query.ExpenseBookQueryObject;
import cn.wolfcode.edu.service.IExpenseBookService;
import cn.wolfcode.edu.util.JsonResult;
import cn.wolfcode.edu.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by ASUS on 2018/7/9.
 */
@Controller
@RequestMapping("expenseBook")
public class ExpenseBookController {

    @Autowired
    private IExpenseBookService expenseBookService;

    @RequestMapping("")
    public String  index(){
        return "expensebook";
    }

    /**
     * 返回所有的支出明细
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(ExpenseBookQueryObject qo){
        try {
            return expenseBookService.query(qo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new PageResult();
    }

    @RequestMapping("changeStatus")
    @ResponseBody
    public JsonResult changeStatus(Long id){
        JsonResult jsonResult = new JsonResult();
        try{
            expenseBookService.changeStatusById(id);
        }catch (Exception e){
            jsonResult.remark("审核失败");
        }
        return jsonResult;
    }
    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(ExpenseBook expenseBook){
        JsonResult jsonResult = new JsonResult();
        try{
            expenseBookService.saveExpenseBook(expenseBook);
        }catch (Exception e){
            jsonResult.remark("保存失败");
        }
        return jsonResult;
    }
}
